<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>书城首页</title>
    <jsp:include page="/abstract/base-head.jsp"></jsp:include>
    <script type="text/javascript">
        // 预加载函数 jQuery 代码应该写在里面
        // 作用 等待 dom 树绘制完成之后 加载方法
        $(function () {
            // ajax add cart use reduce the page refresh
            $(".addCart").click(function () {
                // 点击之后获取参数
                var text = $(this).attr("bookId");
                $.get("cart?method=addAjax&id=" + text,function (data) {
                    $("#totalCount").text(data.totalCount);
                    /** 如果想要在下一页进行保存 放在session中 */
                    $("#bookTitleTop").html("您刚刚将<span style='color: red'>[" + data.bookName + "]</span>加入了购物车中");
                },'json');
            });
        });
    </script>
</head>
<body>

<div id="header">
    <img class="logo_img" alt="" src="static/img/logo.gif" >
    <span class="wel_word">网上书城</span>
    <jsp:include page="/abstract/base-info.jsp"></jsp:include>
</div>
<div id="main">
    <div id="book">
        <div class="book_cond">
            <form action="index" method="get">
                <input type="hidden" name="method" value="pageByPrice">
                价格：<input id="min" type="text" name="min_price" value="${param.min_price == null ? "" : param.min_price}"> 元 -
                <input id="max" type="text" name="max_price" value="${param.max_price == null ? "" : param.max_price}"> 元
                <input type="submit" value="查询" />
            </form>
        </div>
        <div style="text-align: center"><%--<c:out value="${cart.totalCount}" default="0"></c:out> --%>
            <span>您的购物车中有 <span id="totalCount"><c:out value="${cart.totalCount}" default="0"></c:out></span>件商品</span>
            <div>
                <span id="bookTitleTop"></span>
            </div>
        </div>
            <c:forEach items="${list.items}" var="book">
                <div class="b_list">
                    <div class="img_div">
                        <img class="book_img" alt="" src="${book.imgPath}" />
                    </div>
                    <div class="book_info">
                        <div class="book_name">
                            <span class="sp1">书名:</span>
                            <span class="sp2">${book.name}</span>
                        </div>
                        <div class="book_author">
                            <span class="sp1">作者:</span>
                            <span class="sp2">${book.author}</span>
                        </div>
                        <div class="book_price">
                            <span class="sp1">价格:</span>
                            <span class="sp2">${book.price}</span>
                        </div>
                        <div class="book_sales">
                            <span class="sp1">销量:</span>
                            <span class="sp2">${book.sales}</span>
                        </div>
                        <div class="book_amount">
                            <span class="sp1">库存:</span>
                            <span class="sp2">${book.stock}</span>
                        </div>
                        <div class="book_add">
                            <a class="addCart" bookId="${book.id}" href="javascript:void(0);">加入购物车</a><%--cart?method=add&id=${book.id}--%>
                        </div>
                    </div>
               <%--<div class="b_list">
                <div class="img_div">
                    <img class="book_img" alt="" src="static/img/default.jpg" />
                </div>
                <div class="book_info">
                    <div class="book_name">
                        <span class="sp1">书名:</span>
                        <span class="sp2">时间简史</span>
                    </div>
                    <div class="book_author">
                        <span class="sp1">作者:</span>
                        <span class="sp2">霍金</span>
                    </div>
                    <div class="book_price">
                        <span class="sp1">价格:</span>
                        <span class="sp2">￥30.00</span>
                    </div>
                    <div class="book_sales">
                        <span class="sp1">销量:</span>
                        <span class="sp2">230</span>
                    </div>
                    <div class="book_amount">
                        <span class="sp1">库存:</span>
                        <span class="sp2">1000</span>
                    </div>
                    <div class="book_add">
                        <button>加入购物车</button>
                    </div>
                </div>
            </div>--%>
                </div>
            </c:forEach>
        </div>
        <jsp:include page="/abstract/base-paging.jsp"></jsp:include>
    </div>

</div>

<div id="bottom">
		<span>
			尚硅谷书城.Copyright &copy;2015
		</span>
</div>
</body>
</html>